package io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/*
向文本中写入数据
 */
public class WriteString {
    public static void main(String[] args) throws Exception {

        fileOutputStream();
    }

    public static void fileOutputStream() throws IOException {
        // 向文件fos.txt写入文本数据
        FileOutputStream fos = new FileOutputStream("fos.txt",true);
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("请输入想要写入文本的内容，直到输入exit时停止程序");
            String str = scanner.nextLine();
            if ("exit".equalsIgnoreCase(str)){
                break;
            }else fos.write(str.getBytes(StandardCharsets.UTF_8));

        }
        System.out.println("OK,程序结束");
        fos.close();
    }
}
